package com.vision.core.cl.mvp;

import com.allen_sauer.gwt.log.client.Log;
import com.google.gwt.activity.shared.AbstractActivity;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.place.shared.Place;
import com.google.gwt.user.client.ui.AcceptsOneWidget;
import com.vision.core.cl.AppPlace;
import com.vision.core.cl.ClientFactory;
import com.vision.core.cl.ui.MainView;

/**
 * 
 * @author Mark
 * 
 */
public class AppActivity extends AbstractActivity implements MainView.Presenter {

	private AppPlace place;
	private ClientFactory clientFactory;

	public AppActivity(AppPlace place, ClientFactory clientFactory) {
		this.place = place;
		this.clientFactory = clientFactory;
	}

	@Override
	public void start(AcceptsOneWidget containerWidget, EventBus eventBus) {
		if (Log.isTraceEnabled())
			Log.trace("start( " + place.getId() + ")");
		
		clientFactory.getMainView().openTab(place.getId());
	}
	
	@Override
	public String mayStop() {
		String message = clientFactory.getMainView().getBusyMesssage();
		
		if (Log.isTraceEnabled())
			Log.trace("mayStop( " + place.getId() + "): " + message);
		
		return message;
	}
	
	@Override
	public void onCancel() {
		super.onCancel();
	}

	public void goTo(Place place) {
		clientFactory.getPlaceController().goTo(place);
	}

}
